package com.limao.CacheManager;

import com.Hazelcast.Cache;
import com.Hazelcast.CacheFactory;
import com.limao.DBDataClass.CrowdUserParentClass;
import com.limao.DBProvider.CrowdUserParentProvider;
import com.limao.cache.BasicModule;

public class user_parentCacheManager  extends BasicModule{

	private CrowdUserParentProvider provider;
	
	private static user_parentCacheManager instance;

    public static user_parentCacheManager getInstance() {
        return instance;
    }
     
    private Cache<String, CrowdUserParentClass> user_parentManagerCache;

    public user_parentCacheManager() {
    	super("userParentCacheManager");
    	user_parentManagerCache=CacheFactory.createCache("cd_userParentManagerCache");
        initProvider();
    }
    
    @Override
	public void initialize() {
        super.initialize();
        instance=this;
    }
    
    public void ClearObjectCache(String userid)
    {
    	CrowdUserParentClass user =user_parentManagerCache.get(userid);
    	if(user!=null)
    	{
    		user_parentManagerCache.remove(user.userid);
    	}
    }  
 
	

	//查询用户id　上三级的pid
	public CrowdUserParentClass load_user_Parent(int id){
		String key = id + "";
		CrowdUserParentClass obj = user_parentManagerCache.get(key);
		if (obj == null) {
			obj = provider.loadUserParent(id);
			if (obj != null) {
				user_parentManagerCache.put(key, obj);
			}
		}
		
		return obj;
	} 
	

	private void initProvider() {
		if (provider == null) {
			try {
				provider = CrowdUserParentProvider.getInstance();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}


}
